#include<iostream>
using namespace std;

int main()
{
	long long n = 0, m = 0;
	cin >> n >> m;
	char s[10000][10000] = { 0 };
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> s[i][j];
		}
	}
	long long x[1000] = { 0 }, y[1000] = { 0 };
	for (int i = 0; i < m; i++)
	{
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if(s[x[i],y[i]])
		}
	}

	return 0;
}